{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .row{
        margin-top: 10px;
    }
</style>

<article class="page-container">
<form>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">渠道：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select class="form-control" size="1px" name="channel_id" style="padding: 0.6%">
                <option value="" selected="selected">请选择渠道</option>
                {volist name='chanel' id='v'}
                <option value="{$v.id}">{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">问题：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select style=" width: 23%;padding: 0.4% ;display: inline-block" class="form-control goods_category"
                    name="pro_id">
                <option selected="selected" value="">请选择</option>
                {volist name='go' id='v'}
                <option value="{$v.id}">{$v.title}</option>
                {/volist}</select>

            <select style="width: 24%;padding: 0.4%;display: inline-block" class="form-control goods" name="pro_id1">
                <option selected="selected">请选择问题</option>
            </select>

            <select style=" width: 36%;padding: 0.4%;display: inline-block" class="form-control good" name="pro_id2">
                <option selected="selected">请选择问题</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">时间：</label>
        <div class='input-group date' id='datetimepicker2' style="   padding-left: 1%; width: 28%;">
            <input type='text' class="form-control" name="created_time" />
            <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
        </div>



    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1" >地址：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select name="province" class="province form-control" style="width: 25%;padding: 0.4%;display: inline-block" ><option selected="selected">请选择地址</option></select>
            <select name="city" class="city form-control" style="width: 26%;padding: 0.4%;display: inline-block"><option selected="selected">请选择地址</option></select>
            <select name="area" class="area form-control" style="width: 26%;padding: 0.4%;display: inline-block"><option selected="selected">请选择地址</option></select>
            <input type="text" class="form-control" name="addres" placeholder="请输入详细地址" style="padding: 0.4%;width: 20%;display: inline-block">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">联系人：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="form-control" value="{$data.username}" name="contacts"  style="width: 30%" placeholder="请输入联系人">
        </div>
    </div>
    <input type="hidden" value="{$data.customer_id}" name="customer_id">
    <input type="hidden" value="{$data.lai}" name="tui_jian">
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">电话：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="form-control" value="{$data.mobile}" name="telephone"   style="width: 30%" placeholder="请输入联系人电话">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-2">是否有效：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select class="form-control" size="1px" name="state" style="width: 10%;padding: 0.4%">
                <option value="0" selected="selected">有效</option>
                <option value="10">无效</option>

            </select>
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1">备注：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <textarea placeholder="请输入备注" style="margin:0px;width:569px;height: 199px; padding: 18px;" name="remarks" class="form-control"></textarea>
            <!--<input type="text" class="form-control" value="" name="remarks" style="width: 50%" placeholder="请输入备注">-->
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-2 col-sm-1"><span class="c-red">*</span>图片：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <div id="uploader-demo">
                <!--用来存放item-->
                <div id="filePicker">选择图片</div>
                <div id="fileList" class="uploader-list">

                </div>
            </div>

        </div>
    </div>



    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
            <button class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
        </div>
    </div>

</form>
</article>
{include file="public/footer"}
<script>
    $('.radius').click(function () {

            var src = "{:Url('index/Customer/edits')}";
            $.ajax({
                type: 'POST',
                url: src,
                dataType: 'json',
                data:$('form').serializeArray(),
                success: function (data) {
                    var res = JSON.parse(data);
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                            parent.location.reload()
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 1000});
                    }

                },
                error: function (data) {
                    console.log(data.msg);
                },
            });



    });

    $('.goods_category').bind("change", function () {
        //向input输入框中赋值
        goods();
    });
    $(".goods").bind("change", function () {
        good()
    });


    function goods() //市
    {
        var parent_ids = $(".goods_category option:selected").val();
        $.post("{:url('index/order/goods_category')}", {parent_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }

            $('.goods').html(html);
            good();


        });
    }


    function good() {
        var parent_id = $('.goods').val();
        var html;

        if (parent_id) {
            $.post("{:url('index/order/goods_category')}", {parent_id: parent_id}, function (data, textStatus, xhr) {

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";

                    }
                } else {
                    html += "<option value=''>暂无数据</option>";
                }

                $('.good').html(html);

            });
        } else {
            html += "<option value=''>暂无数据</option>";
            $('.good').html(html);
        }

    }
    privance();



    function goods_category() //省
    {
        $.post("{:url('index/order/goods_category')}", {parent_id: '0',}, function(data, textStatus, xhr) {
            var html;
            html+="<option selected='selected'>请选择问题</option>";
            for (var i = 0; i<data.length; i++) {
                html += "<option value='"+data[i]['id']+"'>"+data[i]['title']+"</option>";
            }

            $('.goods_category').html(html);

        });
    }
    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object){
        $(object).parent().remove();
        count-=1;
    }
    var count=1;
    $(function(){
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate:true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>'+
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo[]" type="hidden" value="">'+
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, 100, 100 );
        });



        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
            }


            $percent.css( 'width', percentage * 100 + '%' );
        });
        var s=[];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,res ) {
            var data = JSON.parse(res._raw);
            if(data.errcode==300){
                layer.alert(data.msg);
            }
            var url = data.data;
            count+=1;
            $( '#'+file.id).find("logo").attr("src",url);
            $( '#'+file.id).find("input").val(url);
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });


</script>
</body>
</html>